package com.woniuxy.access.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    /**
     * 队列:    sddfp-queue-bind
     * 交换机:  sddfp-exchange-bind
     * 路由key: bind-card-message
     *
     */
    @Bean
    public Queue queueBind(){
        return new Queue(MQConstant.SDDFP_QUEUE_BIND);
//        return QueueBuilder.durable(MQConstant.SDDFP_QUEUE_BIND).build();
    }
    @Bean
    public DirectExchange exchangeBind(){
        return new DirectExchange(MQConstant.SDDFP_EXCHANGE_BIND);
    }
    @Bean
    public Binding binding(Queue queueBind, DirectExchange exchangeBind) {
        return BindingBuilder.bind(queueBind).to(exchangeBind).with(MQConstant.BIND_CARD_MESSAGE);
    }

    // 消息的转换器，支持发送消息时候传入对象，会自动把对象转换为json格式
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
}